package unit3.part11;

import java.util.Scanner;

/**
 * 数值排序
 */
public class Rank {
    public static void main(String[] args) {
        System.out.println("请任意输入五个正整数数字：");
        int[] nums = new int[5];
        Scanner in = new Scanner(System.in); // 接收用户输入的5个正整数
        for (int i = 0; i < nums.length; i++) {
            nums[i] = in.nextInt();
        }

        // 冒泡排序，升序
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if (nums[j] > nums[j + 1]) {//交换两个数值
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
        }
        //打印排序结果
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }
}
